package com.XiGuaXiaoMe.controller.stu;

import com.XiGuaXiaoMe.dao.userDao;
import com.XiGuaXiaoMe.entity.Users;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

public class UserFindServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        userDao dao=new userDao();
        PrintWriter out;
        //1【调用DAO】将查询命令推送到数据库服务器上，得到所有用户信息【list】
        List<Users> userList=dao.findAll();

        /*req.getRequestDispatcher("/Users/list.jsp").forward(req,resp);*/
        //2【调用响应对象】将用户信息结合<table>标签命令以二进制形式写入到响应体
        resp.setContentType("text/html;charset=utf-8");
        out=resp.getWriter();
        out.print("<table border='2' align='center'>");
        out.print("<tr>");
        out.print("<td>用户编号</td>");
        out.print("<td>用户姓名</td>");
        out.print("<td>用户密码</td>");
        out.print("<td>用户邮箱</td>");
        out.print("<td>操作</td>");
        out.print("</tr>");
        for(Users users:userList){
            out.print("<tr>");
            out.print("<td>"+users.getUserId()+"</td>");
            out.print("<td>"+users.getUserName()+"</td>");
            out.print("<td>******</td>");
            out.print("<td>"+users.getEmail()+"</td>");
            out.print("<td><a href='/MyWeb/user/delete?userid="+users.getUserId()+">删除用户</a></td>");
            out.print("</tr>");
        }
        out.print("</table>");
    }




}
